﻿using System.Collections.Generic;

namespace System.Web.Core
{
    public abstract class BaseRequest
    {
        #region Private Members

        private OrderFields orderFields = new OrderFields();
        private List<RequestDependency> requestDependencies = new List<RequestDependency>();

        #endregion

        #region Public Members

        public List<string> ReturnFields;
        public OrderFields OrderFields
        {
            get
            {
                return orderFields;
            }
        }
        public OperationType Operation;
        public List<RequestDependency> RequestDependencies
        {
            get
            {
                return requestDependencies;
            }
        }

        #endregion

        #region Public Methods

        public virtual string GetReturnFieldString()
        {
            return null;
        }
        protected virtual List<string> GetDefaultReturnFields()
        {
            return null;
        }
        public void AddReturnField(string field)
        {
            if (!string.IsNullOrEmpty(field))
            {
                if (this.ReturnFields == null)
                {
                    this.ReturnFields = new List<string>();
                    this.ReturnFields.Add(field);
                }
                else if (!this.ReturnFields.Contains(field))
                {
                    this.ReturnFields.Add(field);
                }
            }
        }
        public void SetReturnFields(List<string> returnFields)
        {
            this.ReturnFields = returnFields;
        }
        public abstract BaseReply Send(BaseRequestBinder requestBinder);
        protected static TValue GetParameterValue<TValue>(object name)
        {
            return UrlManager.Instance.GetParameterValue<TValue>(name);
        }

        #endregion
    }
}